<template>
	<view class="u-page">
		<view class="u-demo-block">
			<u-form
				labelPosition="left"
				:labelWidth="80" 
				:model="formData" 
				:rules="formRules" 
				ref="form1">
				<!-- 设备号 -->
				<u-form-item 
					label="lotNo" 
					required 
					prop="lotNo" 
					ref="machineNo">
					<u-input
						v-model="formData.lotNo"
						clearable
						:focus="focus.lotNo"
						@focus="lotNoFocus"
						@blur="lotNoBlur">
					</u-input>
				</u-form-item>
			</u-form>
		</view>
		<view class="u-demo-block">
			<YSteps
				:lineNum="0" 
				color="#fff" 
				backgroundColor="#000fff" 
				:infoList="recordTimeLine.resultList"
				@longprs="ysteplongpress">
			</YSteps>
		</view>
	
	
	</view>
</template>

<script>
// 引用时间计算库
import YSteps from '@/components/Y-Steps/Y-Steps2.vue';

//引用dayjs
import dayjs from '@/uni_modules/uview-ui/libs/util/dayjs.js'

import {getFinishedRecordByLotNo} from '@/api/usmRecord/usmBtRecord.js'

export default {
	components: {
		YSteps
	},
	data() {
		return {
			formData :{
				lotNo:'',
			},
			formRules:{
			
			},
			focus:{
				lotNo:true
			},
			timer:{
				lotNo:0
			},
			recordTimeLine:{
				resultList:[],
				resultListDTO:[]
			}
			
		};
	},
	onShow() {
		this.lotNoBlur()
	},
	onNavigationBarButtonTap(e) {
		if (e.type === 'menu') {
			// this.showMenuDrawer();
		} else if (e.type === 'home') {
			uni.reLaunch({
				url: '/pages/index/index'
			});
		}
	},
	onUnload() {
		clearTimeout(this.timer.lotNo)
	},
	methods: {
		lotNoFocus(){
			uni.$u.sleep(100).then(() => {
				// #ifdef APP-PLUS
				uni.hideKeyboard();
				// #endif
			})
		},
		lotNoBlur(){
			const that=this;
			this.timer.lotNo = setTimeout(()=>{
				if(this.formData.lotNo.length<1) return 
				that.recordTimeLine.resultList=[]
				that.recordTimeLine.resultListDTO=[]
				getFinishedRecordByLotNo({lotNo:that.formData.lotNo})
				.then(res=>{
					if(uni.$u.test.array(res.data)){
						res.data.forEach(item=>{
							that.recordTimeLine.resultList.push({
								date: item.usmBtRecord.recordTimeDT,
								info: "机台:" + item.usmBtRecord.machineNo +"\n"+"合计良品:" + (item.usmBtRecord.okCount1+item.usmBtRecord.okCount2+item.usmBtRecord.okCount3+item.usmBtRecord.okCount4)
							})
							that.recordTimeLine.resultListDTO.push(item)
						})
					}
					if(uni.$u.test.isEmpty(res.data)){
						uni.$u.toast("无数据")
					}
				})
			},666)
		},
		ysteplongpress(e){
			uni.navigateTo({
				url:'/pages/U-DBSU-statistial-input/U-DBSU-statistial-edit?recordID='+this.recordTimeLine.resultListDTO[e].usmBtRecord.recordID
			})
		}
	}
};
</script>

<style lang="scss" scoped>
.echo {
	margin-left: 80px;
	font-size: 16px;
}
.u-radio {
	margin-bottom: 8px;
	&:last-child {
		margin-bottom: 0px;
	}
}
.poputview {
	width: 375rpx;
	background-color: palegoldenrod;
	word-wrap: break-word;
	word-break: break-all;
}

// scoped穿透
.poputview ::v-deep .u-cell__label {
	font-size: 14px;
}
</style>
